<template>
  <div>
    <commonBox one="商品管理" tow="商品列表"> </commonBox>
    <el-row :gutter="20">
      <el-col :span="10">
        <el-input
          placeholder="请输入内容"
          clearable
          @clear="iptcolse"
          v-model="datainfo.query"
          class="input-with-select"
        >
          <el-button
            slot="append"
            icon="el-icon-search"
            @click="search"
          ></el-button>
        </el-input>
      </el-col>
      <el-col :span="4">
        <el-button type="primary" @click="pushrouter">添加商品</el-button>
      </el-col>
    </el-row>
    <!-- 表格 -->
    <el-table :data="getlist" style="width: 100%">
      <el-table-column type="index" label="#"> </el-table-column>

      <el-table-column prop="goods_name" label="商品名称"> </el-table-column>
      <el-table-column prop="goods_price" label="商品价格（元）" width="90px">
      </el-table-column>
      <el-table-column prop="goods_weight" label="商品重量" width="90px">
      </el-table-column>
      <el-table-column label="创建时间" width="160px">
        <template slot-scope="scope">
          {{ scope.row.add_time | filfrom }}
        </template>
      </el-table-column>
      <el-table-column label="操作" width="150px">
        <template slot-scope="scope">
          <el-button type="primary" icon="el-icon-edit"></el-button>
          <el-button type="danger" icon="el-icon-delete"></el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页功能 -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="datainfo.pagenum"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="datainfo.pagesize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="400"
    >
    </el-pagination>
  </div>
</template>

<script>
export default {
  data() {
    return {
      // 列表数据
      getlist: [],
      // 请求参数
      datainfo: {
        query: "",
        pagenum: 1,
        pagesize: 5,
      },
      total: 0,
    };
  },
  created() {
    this.getlistdata();
  },
  methods: {
    async getlistdata() {
      const { data: res } = await this.$http.get("goods", {
        params: this.datainfo,
      });
      console.log(res);
      this.getlist = res.data.goods;
      this.total = res.data.total;
    },
    // 页面的大小
    handleSizeChange(val) {
      this.datainfo.pagesize = val;
      this.getlistdata();
    },
    // 当前的页面
    handleCurrentChange(val) {
      this.datainfo.pagenum = val;
      this.getlistdata();
    },
    // 编程时导航

    pushrouter() {
      this.$router.push("/goods/app");
    },
    // 搜索
    search() {
      this.getlistdata();
    },
    // 关闭input时触发
    iptcolse() {
      this.getlistdata();
    },
  },
};
</script>

<style lang="less" scoped>
</style>